//
//  LCWWelcomeViewController.swift
//  MyWB
//
//  Created by 李成万 on 16/6/26.
//  Copyright © 2016年 李成万. All rights reserved.
//

import UIKit
import SnapKit
import SDWebImage
class LCWWelcomeViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        setupUI()
    }
    override func viewDidAppear(animated: Bool) {
        
        iconImageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(self.view).offset(100)
        }
        
        UIView.animateWithDuration(1, delay: 1, usingSpringWithDamping: 0.5, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                UIView.animateWithDuration(0.25, animations: { () -> Void in
                    self.welcomeLabel.alpha = 1
                    }, completion: { (_) -> Void in
                        NSNotificationCenter.defaultCenter().postNotificationName(SwitchRootVc, object: "welcome")
                })
        }
    }
    
    func setupUI(){
        
        view = bgImageView
        
        view.addSubview(iconImageView)
        view.addSubview(welcomeLabel)
        
        iconImageView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.view)
            make.top.equalTo(self.view).offset(400)
            make.size.equalTo(CGSizeMake(90, 90))
            
        }
        
        welcomeLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconImageView.snp_bottom).offset(20)
            make.centerX.equalTo(self.view)
            
        }
    }
    
    private lazy var bgImageView : UIImageView = UIImageView(imageName: "ad_background")
    private lazy var iconImageView : UIImageView = {
       
        let img = UIImageView(imageName: "avatar_default_big")
        img.layer.cornerRadius = 45
        img.layer.masksToBounds = true
        
        img.layer.masksToBounds = true

img.sd_setImageWithURL(NSURL(string:LCWUserAccountTools.sharedTool.userAccount?.avatar_large ?? ""), placeholderImage: UIImage(named: "avatar_default_big"))
        return img
    }()
    private lazy var welcomeLabel : UILabel = {
       
        let label = UILabel()
        label.text = "欢迎回来"
        label.textAlignment = .Center
        label.font = UIFont.systemFontOfSize(15)
        label.textColor = UIColor.grayColor()
        label.alpha = 0
        return label
    }()
    
}
